﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Net;
using System.IO;

namespace kegg_service
{

    public partial class Definition
    {
        /// <summary>
        /// Class constructor
        /// </summary>
        /// <param name="entry_id">ID of the object</param>
        /// <param name="definition">Definition of the object</param>
        public Definition(string entry_idField, string definitionField)
        {
            this.entry_idField = entry_idField;

            this.definitionField = definitionField;
        }

        /// <summary>
        /// ID of the object
        /// </summary>
        private string entry_idField;

        /// <summary>
        /// Definition of the object
        /// </summary>
        private string definitionField;

        /// <remarks/>
        public string entry_id
        {
            get
            {
                return this.entry_idField;
            }
            set
            {
                this.entry_idField = value;
            }
        }

        /// <remarks/>
        public string definition
        {
            get
            {
                return this.definitionField;
            }
            set
            {
                this.definitionField = value;
            }
        }
    }

    public partial class StructureAlignment
    {

        /// <summary>
        /// Class constructor
        /// </summary>
        public StructureAlignment(string target_idField, float scoreField, int[] query_nodesField, int[] target_nodesField)
        {
            this.target_idField = target_idField;

            this.scoreField = scoreField;

            this.query_nodesField = query_nodesField;

            this.target_nodesField = target_nodesField;
        }

        private string target_idField;

        private float scoreField;

        private int[] query_nodesField;

        private int[] target_nodesField;

        /// <remarks/>
        public string target_id
        {
            get
            {
                return this.target_idField;
            }
            set
            {
                this.target_idField = value;
            }
        }

        /// <remarks/>
        public float score
        {
            get
            {
                return this.scoreField;
            }
            set
            {
                this.scoreField = value;
            }
        }

        /// <remarks/>
        public int[] query_nodes
        {
            get
            {
                return this.query_nodesField;
            }
            set
            {
                this.query_nodesField = value;
            }
        }

        /// <remarks/>
        public int[] target_nodes
        {
            get
            {
                return this.target_nodesField;
            }
            set
            {
                this.target_nodesField = value;
            }
        }
    }

    public partial class Subtype
    {
        public Subtype(string relationField, int element_idField, string typeField)
        {
            this.relationField = relationField;

            this.element_idField = element_idField;

            this.typeField = typeField;
        }

        private string relationField;

        private int element_idField;

        private string typeField;

        /// <remarks/>
        public string relation
        {
            get
            {
                return this.relationField;
            }
            set
            {
                this.relationField = value;
            }
        }

        /// <remarks/>
        public int element_id
        {
            get
            {
                return this.element_idField;
            }
            set
            {
                this.element_idField = value;
            }
        }

        /// <remarks/>
        public string type
        {
            get
            {
                return this.typeField;
            }
            set
            {
                this.typeField = value;
            }
        }
    }

    public partial class PathwayElementRelation
    {
        public PathwayElementRelation(int element_id1Field, int element_id2Field, string typeField, Subtype[] subtypesField)
        {
            this.element_id1Field = element_id1Field;

            this.element_id2Field = element_id2Field;

            this.typeField = typeField;

            this.subtypesField = subtypesField;
        }

        private int element_id1Field;

        private int element_id2Field;

        private string typeField;

        private Subtype[] subtypesField;

        /// <remarks/>
        public int element_id1
        {
            get
            {
                return this.element_id1Field;
            }
            set
            {
                this.element_id1Field = value;
            }
        }

        /// <remarks/>
        public int element_id2
        {
            get
            {
                return this.element_id2Field;
            }
            set
            {
                this.element_id2Field = value;
            }
        }

        /// <remarks/>
        public string type
        {
            get
            {
                return this.typeField;
            }
            set
            {
                this.typeField = value;
            }
        }

        /// <remarks/>
        public Subtype[] subtypes
        {
            get
            {
                return this.subtypesField;
            }
            set
            {
                this.subtypesField = value;
            }
        }
    }

    public partial class PathwayElement
    {

        public PathwayElement(int element_idField, string typeField, string[] namesField, int[] componentsField)
        {
            this.element_idField = element_idField;

            this.typeField = typeField;

            this.namesField = namesField;

            this.componentsField = componentsField;
        }

        private int element_idField;

        private string typeField;

        private string[] namesField;

        private int[] componentsField;

        /// <remarks/>
        public int element_id
        {
            get
            {
                return this.element_idField;
            }
            set
            {
                this.element_idField = value;
            }
        }

        /// <remarks/>
        public string type
        {
            get
            {
                return this.typeField;
            }
            set
            {
                this.typeField = value;
            }
        }

        /// <remarks/>
        public string[] names
        {
            get
            {
                return this.namesField;
            }
            set
            {
                this.namesField = value;
            }
        }

        /// <remarks/>
        public int[] components
        {
            get
            {
                return this.componentsField;
            }
            set
            {
                this.componentsField = value;
            }
        }
    }

    public partial class MotifResult
    {

        public MotifResult(string motif_idField, string definitionField, string genes_idField, int start_positionField,
                               int end_positionField, float scoreField, double evalueField)
        {
            this.motif_idField = motif_idField;

            this.definitionField = definitionField;

            this.genes_idField = genes_idField;

            this.start_positionField = start_positionField;

            this.end_positionField = end_positionField;

            this.scoreField = scoreField;

            this.evalueField = evalueField;
        }


        private string motif_idField;

        private string definitionField;

        private string genes_idField;

        private int start_positionField;

        private int end_positionField;

        private float scoreField;

        private double evalueField;

        /// <remarks/>
        public string motif_id
        {
            get
            {
                return this.motif_idField;
            }
            set
            {
                this.motif_idField = value;
            }
        }

        /// <remarks/>
        public string definition
        {
            get
            {
                return this.definitionField;
            }
            set
            {
                this.definitionField = value;
            }
        }

        /// <remarks/>
        public string genes_id
        {
            get
            {
                return this.genes_idField;
            }
            set
            {
                this.genes_idField = value;
            }
        }

        /// <remarks/>
        public int start_position
        {
            get
            {
                return this.start_positionField;
            }
            set
            {
                this.start_positionField = value;
            }
        }

        /// <remarks/>
        public int end_position
        {
            get
            {
                return this.end_positionField;
            }
            set
            {
                this.end_positionField = value;
            }
        }

        /// <remarks/>
        public float score
        {
            get
            {
                return this.scoreField;
            }
            set
            {
                this.scoreField = value;
            }
        }

        /// <remarks/>
        public double evalue
        {
            get
            {
                return this.evalueField;
            }
            set
            {
                this.evalueField = value;
            }
        }
    }

    public partial class SSDBRelation
    {

        public SSDBRelation(string genes_id1Field, string genes_id2Field, int sw_scoreField, float bit_scoreField,
                               float identityField, int overlapField, int start_position1Field, int end_position1Field,
                                   int start_position2Field, int end_position2Field, bool best_flag_1to2Field,
                                        bool best_flag_2to1Field, string definition1Field, string definition2Field, int length1Field, int length2Field)
        {
            this.genes_id1Field = genes_id1Field;

            this.genes_id2Field = genes_id2Field;

            this.sw_scoreField = sw_scoreField;

            this.bit_scoreField = bit_scoreField;

            this.identityField = identityField;

            this.overlapField = overlapField;

            this.start_position1Field = start_position1Field;

            this.end_position1Field = end_position1Field;

            this.start_position2Field = start_position2Field;

            this.end_position2Field = end_position2Field;

            this.best_flag_1to2Field = best_flag_1to2Field;

            this.best_flag_2to1Field = best_flag_2to1Field;

            this.definition1Field = definition1Field;

            this.definition2Field = definition2Field;

            this.length1Field = length1Field;

            this.length2Field = length2Field;
        }


        private string genes_id1Field;

        private string genes_id2Field;

        private int sw_scoreField;

        private float bit_scoreField;

        private float identityField;

        private int overlapField;

        private int start_position1Field;

        private int end_position1Field;

        private int start_position2Field;

        private int end_position2Field;

        private bool best_flag_1to2Field;

        private bool best_flag_2to1Field;

        private string definition1Field;

        private string definition2Field;

        private int length1Field;

        private int length2Field;

        /// <remarks/>
        public string genes_id1
        {
            get
            {
                return this.genes_id1Field;
            }
            set
            {
                this.genes_id1Field = value;
            }
        }

        /// <remarks/>
        public string genes_id2
        {
            get
            {
                return this.genes_id2Field;
            }
            set
            {
                this.genes_id2Field = value;
            }
        }

        /// <remarks/>
        public int sw_score
        {
            get
            {
                return this.sw_scoreField;
            }
            set
            {
                this.sw_scoreField = value;
            }
        }

        /// <remarks/>
        public float bit_score
        {
            get
            {
                return this.bit_scoreField;
            }
            set
            {
                this.bit_scoreField = value;
            }
        }

        /// <remarks/>
        public float identity
        {
            get
            {
                return this.identityField;
            }
            set
            {
                this.identityField = value;
            }
        }

        /// <remarks/>
        public int overlap
        {
            get
            {
                return this.overlapField;
            }
            set
            {
                this.overlapField = value;
            }
        }

        /// <remarks/>
        public int start_position1
        {
            get
            {
                return this.start_position1Field;
            }
            set
            {
                this.start_position1Field = value;
            }
        }

        /// <remarks/>
        public int end_position1
        {
            get
            {
                return this.end_position1Field;
            }
            set
            {
                this.end_position1Field = value;
            }
        }

        /// <remarks/>
        public int start_position2
        {
            get
            {
                return this.start_position2Field;
            }
            set
            {
                this.start_position2Field = value;
            }
        }

        /// <remarks/>
        public int end_position2
        {
            get
            {
                return this.end_position2Field;
            }
            set
            {
                this.end_position2Field = value;
            }
        }

        /// <remarks/>
        public bool best_flag_1to2
        {
            get
            {
                return this.best_flag_1to2Field;
            }
            set
            {
                this.best_flag_1to2Field = value;
            }
        }

        /// <remarks/>
        public bool best_flag_2to1
        {
            get
            {
                return this.best_flag_2to1Field;
            }
            set
            {
                this.best_flag_2to1Field = value;
            }
        }

        /// <remarks/>
        public string definition1
        {
            get
            {
                return this.definition1Field;
            }
            set
            {
                this.definition1Field = value;
            }
        }

        /// <remarks/>
        public string definition2
        {
            get
            {
                return this.definition2Field;
            }
            set
            {
                this.definition2Field = value;
            }
        }

        /// <remarks/>
        public int length1
        {
            get
            {
                return this.length1Field;
            }
            set
            {
                this.length1Field = value;
            }
        }

        /// <remarks/>
        public int length2
        {
            get
            {
                return this.length2Field;
            }
            set
            {
                this.length2Field = value;
            }
        }
    }

    public partial class LinkDBRelation
    {

        public LinkDBRelation(string entry_id1Field, string entry_id2Field, string typeField, string pathField)
        {
            this.entry_id1Field = entry_id1Field;

            this.entry_id2Field = entry_id2Field;

            this.typeField = typeField;

            this.pathField = pathField;
        }

        private string entry_id1Field;

        private string entry_id2Field;

        private string typeField;

        private string pathField;

        /// <remarks/>
        public string entry_id1
        {
            get
            {
                return this.entry_id1Field;
            }
            set
            {
                this.entry_id1Field = value;
            }
        }

        /// <remarks/>
        public string entry_id2
        {
            get
            {
                return this.entry_id2Field;
            }
            set
            {
                this.entry_id2Field = value;
            }
        }

        /// <remarks/>
        public string type
        {
            get
            {
                return this.typeField;
            }
            set
            {
                this.typeField = value;
            }
        }

        /// <remarks/>
        public string path
        {
            get
            {
                return this.pathField;
            }
            set
            {
                this.pathField = value;
            }
        }
    }


    /// <summary>
    /// function definitions from http://www.kegg.jp/kegg/docs/keggapi_manual.html
    /// </summary>
    public class Kegg
    {
        ///create header function text with parametrs
        /// example: 
        ///<tns:get_enzymes_by_gene><genes_id xsi:type="xsd:string">eco:b0002</genes_id></tns:get_enzymes_by_gene>
        private string CreateHeader(string function, params object[] list)
        {
            string str = "";

            str = "<tns:" + function + ">";
            if (list.GetLength(0) > 0)
            {

                string tmp = "";
                int j = 0;
                for (int i = 0; i < list.GetLength(0); i++)
                {
                    if (j == 0)
                    {
                        str = str + "<" + list[i].ToString();
                        tmp = list[i].ToString();
                    }
                    if (j == 1)
                        str = str + " xsi:type=\"xsd:" + list[i].ToString() + "\">";
                    if (j == 2)
                    {
                        str = str + list[i].ToString();
                        str = str + "</" + tmp + ">";
                    }


                    if (j == 2)
                    {
                        j = 0;
                        tmp = "";
                    }

                    else
                        j++;
                }

                str = str + "</tns:" + function + ">";
            }
            else
                str = str + "</tns:" + function + ">";


            return str;
        }

        //get data from kegg
        //parametrs: function name, parametr array:  input element name, input element type, input element value 
        XmlDocument GetKeddData(string function, params object[] list)
        {
            //create document to return
            XmlDocument xmlDoc = new XmlDocument();

            //url of the service
            string url = "http://soap.genome.jp/keggapi/request_v6.2.cgi";

            //header text that is sent to the service
            string headerText = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope " +
                " xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
                " xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:tns=\"SOAP/KEGG\" " +
                " xmlns:types=\"SOAP/KEGG/encodedTypes\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
                " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body soap:encodingStyle=" +
                "\"http://schemas.xmlsoap.org/soap/encoding/\"> " + CreateHeader(function, list) + "</soap:Body></soap:Envelope>";

            //create request
            HttpWebRequest req;
            try { req = (HttpWebRequest)HttpWebRequest.Create(url); }
            catch (Exception err) { return null; }

            //add properties of the request
            req.Method = "POST";
            req.ContentType = "text/xml; charset=utf-8";

            //get header length
            byte[] postDataBytes = Encoding.UTF8.GetBytes(headerText.Trim());
            req.ContentLength = postDataBytes.Length;

            //send request to the service
            Stream postDataStream = req.GetRequestStream();
            postDataStream.Write(postDataBytes, 0, postDataBytes.Length);
            postDataStream.Close();

            //create response
            HttpWebResponse resp;
            try { resp = (HttpWebResponse)req.GetResponse(); }
            catch (WebException err)
            {
                resp = (HttpWebResponse)err.Response;
                if (resp == null) { return null; }
            }
            catch (Exception err) { return null; }

            //receive response
            Stream rcvStream = resp.GetResponseStream();
            xmlDoc.Load(rcvStream);

            //close opened connections
            resp.Close();
            rcvStream.Close();

            return xmlDoc;

        }

        public List<Definition> list_databases()
        {
            //load data from KEGG and search items in the file
            //parametrs: function name, parametr array:  input element name, input element type, input element value 
            XmlNodeList list = GetKeddData("list_databases").GetElementsByTagName("item");

            //create list of definition objects
            List<Definition> definition = new List<Definition>();

            //parse xml elements into definition object and fill the list of definitions
            foreach (XmlNode e in list)
            {
                definition.Add(new Definition(e["entry_id"].InnerText, e["definition"].InnerText));
            }

            return definition;
        }

        public List<Definition> list_organisms()
        {

            //load data from KEGG and search items in the file
            XmlNodeList list = GetKeddData("list_organisms").GetElementsByTagName("item");

            //create list of definition objects
            List<Definition> definition = new List<Definition>();

            //parse xml elements into definition object and fill the list of definitions
            foreach (XmlNode e in list)
            {
                definition.Add(new Definition(e["entry_id"].InnerText, e["definition"].InnerText));
            }

            return definition;
        }

        public string[] get_enzymes_by_gene(string genes_id)
        {

            //load data from KEGG and search items in the file
            //parametrs: function name, parametr array:  input element name, input element type, input element value 
            XmlNodeList list = GetKeddData("get_enzymes_by_gene", "genes_id", "string",
                                                genes_id).GetElementsByTagName("item");

            //create array of definition objects
            string[] str = new string[list.Count];

            int i = 0;

            //parse xml elements into definition object and fill the list of definitions
            foreach (XmlElement e in list)
            {
                str[i] = e.InnerText;
                i++;
            }

            return str;
        }

        public List<Definition> list_pathways(string org)
        {
            //load data from KEGG and search items in the file
            //parametrs: function name, parametr array:  input element name, input element type, input element value 
            XmlNodeList list = GetKeddData("list_pathways", "org", "string", org).GetElementsByTagName("item");

            //create list of definition objects
            List<Definition> definition = new List<Definition>();

            //parse xml elements into definition object and fill the list of definitions
            foreach (XmlNode e in list)
            {
                definition.Add(new Definition(e["entry_id"].InnerText, e["definition"].InnerText));
            }

            return definition;
        }

        public List<MotifResult> get_motifs_by_gene(string genes_id, string db)
        {
            //example of MotifResult constructor
            // public MotifResult(string motif_idField, string definitionField, string genes_idField, int start_positionField,
            //                    int end_positionField, float scoreField, double evalueField)


            //load data from KEGG and search items in the file
            //parametrs: function name, parametr array:  input element name, input element type, input element value 
            XmlNodeList list = GetKeddData("get_motifs_by_gene", "genes_id", "string", genes_id,
                                                "db", "string", db).GetElementsByTagName("item");

            //create list of definition objects
            List<MotifResult> motifResult = new List<MotifResult>();

            //parse xml elements into definition object and fill the list of definitions
            foreach (XmlNode e in list)
            {
                motifResult.Add(new MotifResult(e["motif_id"].InnerText, e["definition"].InnerText, e["genes_id"].InnerText,
                                    int.Parse(e["start_position"].InnerText), int.Parse(e["end_position"].InnerText),
                                        float.Parse(e["score"].InnerText), double.Parse(e["evalue"].InnerText.Replace(".", ","))));
            }



            return motifResult;
        }



        //public Definition[] list_ko_classes(string class_id)
        //{
        //    object[] results = this.Invoke("list_ko_classes", new object[] {
        //                class_id});
        //    return ((Definition[])(results[0]));
        //}

        public string binfo(string db)
        {
            //load data from KEGG and search items in the file
            //parametrs: function name, parametr array:  input element name, input element type, input element value 
            XmlNodeList list = GetKeddData("binfo", "db", "string", db).GetElementsByTagName("return");

            //create definition object
            string binfo = list[0].InnerText;

            return binfo;
        }

        public string[] get_compounds_by_reaction(string reaction_id)
        {
            XmlNodeList list = GetKeddData("get_compounds_by_reaction", "reaction_id", "string",
                                              reaction_id).GetElementsByTagName("item");

            //create array of definition objects
            string[] str = new string[list.Count];

            int i = 0;

            //parse xml elements into definition object and fill the list of definitions
            foreach (XmlElement e in list)
            {
                str[i] = e.InnerText;
                i++;
            }

            return str;
        }

        public string[] get_reactions_by_compound(string compound_id)
        {

            XmlNodeList list = GetKeddData("get_reactions_by_compound", "compound_id", "string",
                                               compound_id).GetElementsByTagName("item");

            //create array of definition objects
            string[] str = new string[list.Count];

            int i = 0;

            //parse xml elements into definition object and fill the list of definitions
            foreach (XmlElement e in list)
            {
                str[i] = e.InnerText;
                i++;
            }

            return str;
        }

        public string bfind(string keyword)
        {
            XmlNodeList list = GetKeddData("bfind", "db", "string", keyword).GetElementsByTagName("return");

            //create definition object
            string binfo = list[0].InnerText;

            return binfo;
        }


        public string[] get_reactions_by_enzyme(string enzyme_id)
        {
            XmlNodeList list = GetKeddData("get_reactions_by_enzyme", "enzyme_id", "string",
                                              enzyme_id).GetElementsByTagName("item");

            //create array of definition objects
            string[] str = new string[list.Count];

            int i = 0;

            //parse xml elements into definition object and fill the list of definitions
            foreach (XmlElement e in list)
            {
                str[i] = e.InnerText;
                i++;
            }

            return str;
        }

        //public string[] get_enzymes_by_glycan(string glycan_id)
        //{
        //    object[] results = this.Invoke("get_enzymes_by_glycan", new object[] {
        //                glycan_id});
        //    return ((string[])(results[0]));
        //}

        //public string[] get_enzymes_by_compound(string compound_id)
        //{
        //    object[] results = this.Invoke("get_enzymes_by_compound", new object[] {
        //                compound_id});
        //    return ((string[])(results[0]));
        //}



        //public string bget(string @string)
        //{
        //    object[] results = this.Invoke("bget", new object[] {
        //                @string});
        //    return ((string)(results[0]));
        //}



        //public string btit(string @string)
        //{
        //    object[] results = this.Invoke("btit", new object[] {
        //                @string});
        //    return ((string)(results[0]));
        //}

        //public string bconv(string @string)
        //{
        //    object[] results = this.Invoke("bconv", new object[] {
        //                @string});
        //    return ((string)(results[0]));
        //}

        //public LinkDBRelation[] get_linkdb_by_entry(string entry_id, string db, int offset, int limit)
        //{
        //    object[] results = this.Invoke("get_linkdb_by_entry", new object[] {
        //                entry_id,
        //                db,
        //                offset,
        //                limit});
        //    return ((LinkDBRelation[])(results[0]));
        //}

        //public SSDBRelation[] get_best_neighbors_by_gene(string genes_id, int offset, int limit)
        //{
        //    object[] results = this.Invoke("get_best_neighbors_by_gene", new object[] {
        //                genes_id,
        //                offset,
        //                limit});
        //    return ((SSDBRelation[])(results[0]));
        //}

        //public SSDBRelation[] get_best_best_neighbors_by_gene(string genes_id, int offset, int limit)
        //{
        //    object[] results = this.Invoke("get_best_best_neighbors_by_gene", new object[] {
        //                genes_id,
        //                offset,
        //                limit});
        //    return ((SSDBRelation[])(results[0]));
        //}

        //public SSDBRelation[] get_reverse_best_neighbors_by_gene(string genes_id, int offset, int limit)
        //{
        //    object[] results = this.Invoke("get_reverse_best_neighbors_by_gene", new object[] {
        //                genes_id,
        //                offset,
        //                limit});
        //    return ((SSDBRelation[])(results[0]));
        //}

        //public SSDBRelation[] get_paralogs_by_gene(string genes_id, int offset, int limit)
        //{
        //    object[] results = this.Invoke("get_paralogs_by_gene", new object[] {
        //                genes_id,
        //                offset,
        //                limit});
        //    return ((SSDBRelation[])(results[0]));
        //}




        //public Definition[] get_genes_by_motifs(string[] motif_id_list, int offset, int limit)
        //{
        //    object[] results = this.Invoke("get_genes_by_motifs", new object[] {
        //                motif_id_list,
        //                offset,
        //                limit});
        //    return ((Definition[])(results[0]));
        //}

        //public string[] get_ko_by_gene(string genes_id)
        //{
        //    object[] results = this.Invoke("get_ko_by_gene", new object[] {
        //                genes_id});
        //    return ((string[])(results[0]));
        //}


        //public Definition[] get_ko_by_ko_class(string class_id)
        //{
        //    object[] results = this.Invoke("get_ko_by_ko_class", new object[] {
        //                class_id});
        //    return ((Definition[])(results[0]));
        //}

        //public Definition[] get_genes_by_ko(string ko_id, string org)
        //{
        //    object[] results = this.Invoke("get_genes_by_ko", new object[] {
        //                ko_id,
        //                org});
        //    return ((Definition[])(results[0]));
        //}

        //public Definition[] get_genes_by_ko_class(string class_id, string org, int offset, int limit)
        //{
        //    object[] results = this.Invoke("get_genes_by_ko_class", new object[] {
        //                class_id,
        //                org,
        //                offset,
        //                limit});
        //    return ((Definition[])(results[0]));
        //}

        //public PathwayElement[] get_elements_by_pathway(string pathway_id)
        //{
        //    object[] results = this.Invoke("get_elements_by_pathway", new object[] {
        //                pathway_id});
        //    return ((PathwayElement[])(results[0]));
        //}

        //public PathwayElementRelation[] get_element_relations_by_pathway(string pathway_id)
        //{
        //    object[] results = this.Invoke("get_element_relations_by_pathway", new object[] {
        //                pathway_id});
        //    return ((PathwayElementRelation[])(results[0]));
        //}

        //public string color_pathway_by_elements(string pathway_id, int[] element_list, string[] fg_color_list, string[] bg_color_list)
        //{
        //    object[] results = this.Invoke("color_pathway_by_elements", new object[] {
        //                pathway_id,
        //                element_list,
        //                fg_color_list,
        //                bg_color_list});
        //    return ((string)(results[0]));
        //}

        //public string get_html_of_colored_pathway_by_elements(string pathway_id, int[] element_list, string[] fg_color_list, string[] bg_color_list)
        //{
        //    object[] results = this.Invoke("get_html_of_colored_pathway_by_elements", new object[] {
        //                pathway_id,
        //                element_list,
        //                fg_color_list,
        //                bg_color_list});
        //    return ((string)(results[0]));
        //}

        //public string mark_pathway_by_objects(string pathway_id, string[] object_id_list)
        //{
        //    object[] results = this.Invoke("mark_pathway_by_objects", new object[] {
        //                pathway_id,
        //                object_id_list});
        //    return ((string)(results[0]));
        //}

        //public string color_pathway_by_objects(string pathway_id, string[] object_id_list, string[] fg_color_list, string[] bg_color_list)
        //{
        //    object[] results = this.Invoke("color_pathway_by_objects", new object[] {
        //                pathway_id,
        //                object_id_list,
        //                fg_color_list,
        //                bg_color_list});
        //    return ((string)(results[0]));
        //}

        //public string get_html_of_marked_pathway_by_objects(string pathway_id, string[] object_id_list)
        //{
        //    object[] results = this.Invoke("get_html_of_marked_pathway_by_objects", new object[] {
        //                pathway_id,
        //                object_id_list});
        //    return ((string)(results[0]));
        //}

        //public string get_html_of_colored_pathway_by_objects(string pathway_id, string[] object_id_list, string[] fg_color_list, string[] bg_color_list)
        //{
        //    object[] results = this.Invoke("get_html_of_colored_pathway_by_objects", new object[] {
        //                pathway_id,
        //                object_id_list,
        //                fg_color_list,
        //                bg_color_list});
        //    return ((string)(results[0]));
        //}

        //public string[] get_genes_by_pathway(string pathway_id)
        //{
        //    object[] results = this.Invoke("get_genes_by_pathway", new object[] {
        //                pathway_id});
        //    return ((string[])(results[0]));
        //}

        //public string[] get_enzymes_by_pathway(string pathway_id)
        //{
        //    object[] results = this.Invoke("get_enzymes_by_pathway", new object[] {
        //                pathway_id});
        //    return ((string[])(results[0]));
        //}

        //public string[] get_reactions_by_pathway(string pathway_id)
        //{
        //    object[] results = this.Invoke("get_reactions_by_pathway", new object[] {
        //                pathway_id});
        //    return ((string[])(results[0]));
        //}

        //public string[] get_pathways_by_genes(string[] genes_id_list)
        //{
        //    object[] results = this.Invoke("get_pathways_by_genes", new object[] {
        //                genes_id_list});
        //    return ((string[])(results[0]));
        //}


        //public string[] get_pathways_by_enzymes(string[] enzyme_id_list)
        //{
        //    object[] results = this.Invoke("get_pathways_by_enzymes", new object[] {
        //                enzyme_id_list});
        //    return ((string[])(results[0]));
        //}

        //public string[] get_pathways_by_reactions(string[] reaction_id_list)
        //{
        //    object[] results = this.Invoke("get_pathways_by_reactions", new object[] {
        //                reaction_id_list});
        //    return ((string[])(results[0]));
        //}

        //public string[] get_linked_pathways(string pathway_id)
        //{
        //    object[] results = this.Invoke("get_linked_pathways", new object[] {
        //                pathway_id});
        //    return ((string[])(results[0]));
        //}

        //public string[] get_genes_by_enzyme(string enzyme_id, string org)
        //{
        //    object[] results = this.Invoke("get_genes_by_enzyme", new object[] {
        //                enzyme_id,
        //                org});
        //    return ((string[])(results[0]));
        //}




        //public string[] get_enzymes_by_reaction(string reaction_id)
        //{
        //    object[] results = this.Invoke("get_enzymes_by_reaction", new object[] {
        //                reaction_id});
        //    return ((string[])(results[0]));
        //}





        //public string[] get_genes_by_organism(string org, int offset, int limit)
        //{
        //    object[] results = this.Invoke("get_genes_by_organism", new object[] {
        //                org,
        //                offset,
        //                limit});
        //    return ((string[])(results[0]));
        //}

        //public int get_number_of_genes_by_organism(string abbr)
        //{
        //    object[] results = this.Invoke("get_number_of_genes_by_organism", new object[] {
        //                abbr});
        //    return ((int)(results[0]));
        //}

        //public string[] get_reactions_by_glycan(string glycan_id)
        //{
        //    object[] results = this.Invoke("get_reactions_by_glycan", new object[] {
        //                glycan_id});
        //    return ((string[])(results[0]));
        //}




        //public string[] get_pathways_by_compounds(string[] compound_id_list)
        //{
        //    object[] results = this.Invoke("get_pathways_by_compounds", new object[] {
        //                compound_id_list});
        //    return ((string[])(results[0]));
        //}

        //public string[] get_pathways_by_glycans(string[] glycan_id_list)
        //{
        //    object[] results = this.Invoke("get_pathways_by_glycans", new object[] {
        //                glycan_id_list});
        //    return ((string[])(results[0]));
        //}

        //public string[] get_compounds_by_pathway(string pathway_id)
        //{
        //    object[] results = this.Invoke("get_compounds_by_pathway", new object[] {
        //                pathway_id});
        //    return ((string[])(results[0]));
        //}

        //public string[] get_glycans_by_pathway(string pathway_id)
        //{
        //    object[] results = this.Invoke("get_glycans_by_pathway", new object[] {
        //                pathway_id});
        //    return ((string[])(results[0]));
        //}



        //public string[] get_glycans_by_reaction(string reaction_id)
        //{
        //    object[] results = this.Invoke("get_glycans_by_reaction", new object[] {
        //                reaction_id});
        //    return ((string[])(results[0]));
        //}

        //public string[] get_compounds_by_enzyme(string enzyme_id)
        //{
        //    object[] results = this.Invoke("get_compounds_by_enzyme", new object[] {
        //                enzyme_id});
        //    return ((string[])(results[0]));
        //}

        //public string[] get_glycans_by_enzyme(string enzyme_id)
        //{
        //    object[] results = this.Invoke("get_glycans_by_enzyme", new object[] {
        //                enzyme_id});
        //    return ((string[])(results[0]));
        //}

        //public string convert_mol_to_kcf(string mol_text)
        //{
        //    object[] results = this.Invoke("convert_mol_to_kcf", new object[] {
        //                mol_text});
        //    return ((string)(results[0]));
        //}

        //public string[] get_kos_by_pathway(string pathway_id)
        //{
        //    object[] results = this.Invoke("get_kos_by_pathway", new object[] {
        //                pathway_id});
        //    return ((string[])(results[0]));
        //}

        //public string[] get_pathways_by_kos(string[] ko_id_list, string org)
        //{
        //    object[] results = this.Invoke("get_pathways_by_kos", new object[] {
        //                ko_id_list,
        //                org});
        //    return ((string[])(results[0]));
        //}

        //public string[] search_compounds_by_name(string name)
        //{
        //    object[] results = this.Invoke("search_compounds_by_name", new object[] {
        //                name});
        //    return ((string[])(results[0]));
        //}

        //  public string[] search_glycans_by_name(string name) {
        //    object[] results = this.Invoke("search_glycans_by_name", new object[] {
        //                name});
        //    return ((string[])(results[0]));
        //}

        //  public string[] search_compounds_by_composition(string composition)
        //  {
        //      object[] results = this.Invoke("search_compounds_by_composition", new object[] {
        //                composition});
        //      return ((string[])(results[0]));
        //  }

        //  public string[] search_compounds_by_mass(float mass, float range)
        //  {
        //      object[] results = this.Invoke("search_compounds_by_mass", new object[] {
        //                mass,
        //                range});
        //      return ((string[])(results[0]));
        //  }
        //  public string[] search_glycans_by_mass(float mass, float range)
        //  {
        //      object[] results = this.Invoke("search_glycans_by_mass", new object[] {
        //                mass,
        //                range});
        //      return ((string[])(results[0]));
        //  }

        //  public string[] search_glycans_by_composition(string composition)
        //  {
        //      object[] results = this.Invoke("search_glycans_by_composition", new object[] {
        //                composition});
        //      return ((string[])(results[0]));
        //  }

        //  public StructureAlignment[] search_compounds_by_subcomp(string mol, int offset, int limit)
        //  {
        //      object[] results = this.Invoke("search_compounds_by_subcomp", new object[] {
        //                mol,
        //                offset,
        //                limit});
        //      return ((StructureAlignment[])(results[0]));
        //  }

        //  public StructureAlignment[] search_glycans_by_kcam(string kcf, string program, string option, int offset, int limit)
        //  {
        //      object[] results = this.Invoke("search_glycans_by_kcam", new object[] {
        //                kcf,
        //                program,
        //                option,
        //                offset,
        //                limit});
        //      return ((StructureAlignment[])(results[0]));
        //  }


        //  public LinkDBRelation[] get_linkdb_between_databases(string from_db, string to_db, int offset, int limit)
        //  {
        //      object[] results = this.Invoke("get_linkdb_between_databases", new object[] {
        //                from_db,
        //                to_db,
        //                offset,
        //                limit});
        //      return ((LinkDBRelation[])(results[0]));
        //  }

        //  public string[] search_drugs_by_name(string name)
        //  {
        //      object[] results = this.Invoke("search_drugs_by_name", new object[] {
        //                name});
        //      return ((string[])(results[0]));
        //  }


        //  public string[] search_drugs_by_composition(string composition)
        //  {
        //      object[] results = this.Invoke("search_drugs_by_composition", new object[] {
        //                composition});
        //      return ((string[])(results[0]));
        //  }


        //  public string[] search_drugs_by_mass(float mass, float range)
        //  {
        //      object[] results = this.Invoke("search_drugs_by_mass", new object[] {
        //                mass,
        //                range});
        //      return ((string[])(results[0]));
        //  }


        //  public StructureAlignment[] search_drugs_by_subcomp(string mol, int offset, int limit)
        //  {
        //      object[] results = this.Invoke("search_drugs_by_subcomp", new object[] {
        //                mol,
        //                offset,
        //                limit});
        //      return ((StructureAlignment[])(results[0]));
        //  }

        //  public int[] get_references_by_pathway(string pathway_id)
        //  {
        //      object[] results = this.Invoke("get_references_by_pathway", new object[] {
        //                pathway_id});
        //      return ((int[])(results[0]));
        //  }



        //  public string[] get_drugs_by_pathway(string pathway_id)
        //  {
        //      object[] results = this.Invoke("get_drugs_by_pathway", new object[] {
        //                pathway_id});
        //      return ((string[])(results[0]));
        //  }

        //  public string[] get_pathways_by_drugs(string[] drug_id_list)
        //  {
        //      object[] results = this.Invoke("get_pathways_by_drugs", new object[] {
        //                drug_id_list});
        //      return ((string[])(results[0]));
        //  }


    }




}
